<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝积分商城</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <link href="/mall/css/style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/mall/js/tab.js"></script>
    <script type="text/javascript" src="/mall/js/popUP.js"></script>
    <script type="text/javascript" src="/mall/js/popUP.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            if(user){
                //当前页
                var currentPage = 1;
                //总页数  用来判断是否是最后一页
                var pages=1;
                //[] 数组,一个容器 将每次拉倒底部查询的每页数据 数组都存放在里面
                var travelData =[];
                //变量表示 当前页是否已经在查询中 如果是 则不再查询,避免ajax的异步请求发送重复
                var loading= false;//查询状态

                //获取我的游记数据
                function query(){
                    //如果当前为正在查询 则说明ajax已经发送 不需要重复发送
                    if(loading){
                        return;
                    }
                    //每次在发送ajax前,将查询状态改为正在查询,
                    loading = true;
                    $.get("/users/" + user.id+"/orders", {currentPage:currentPage,pageSize: 5}, function (data) {
                        console.log(data);
                        $.merge(travelData,data.list);
                        var json = {list:travelData};
                        $("#dingdan").renderValues(json,{
                            getSum:function (item,value) {
                                var number = $(item).closest("a").find("em").html();
                                $(item).html(number*value);

                            },
                            getBuyId:function (item,value) {
                                console.log("ss");
                                var did = $(item).closest("div").find("input").val();
                                $(item).closest("div").find("a:first").attr("data-did",did);
                                $(item).attr("href","/mine/store/detail.html?id="+value);
                            }/*,
                            getDId:function (item,value) {
                                $(item).attr("data-did",value);
                            }*/
                        });
                        //当前页加1 下次将查询第二页数据
                        currentPage++;
                        //总页数
                        pages = data.pages;
                        //查询请求结果,则将查询状态改为 不在查询中
                        loading = false;
                        $(".aui-well-item-clear").click(function () {
                            var did = $(this).data("did");
                            $(document).dialog({
                                titleText:'温馨提示',
                                type : 'confirm',
                                closeBtnShow: true,
                                content: '确认要删除吗',
                                onClickConfirmBtn: function(){
                                    $.ajax({
                                        type:'DELETE',
                                        url:'/orders/'+did,
                                        success:function () {
                                            $(document).dialog({
                                                titleText: '温馨提示',
                                                content: '删除成功,1秒后刷新',
                                            });
                                            setTimeout(function () {
                                                window.location.reload();
                                            }, 1000);
                                        }
                                    })
                                }
                            });
                            /*$.ajax({
                                type:'DELETE',
                                url:'/orders/'+did,
                                success:function () {
                                    $(document).dialog({
                                        titleText: '温馨提示',
                                        content: '删除成功,1秒后刷新',
                                    });
                                    setTimeout(function () {
                                        window.location.reload();
                                    }, 1000);
                                }
                            })*/
                        });
                    });
                }
                //默认的第一次查第一页数据
                query();

                //给window绑定滚动事件,当window滚动式,调用其中的函数
                $(window).scroll(function () {
                    //判断是否滚动到底部(屏幕高度+HTML滚动超出顶部的高度>=HTML文档的高度)
                    if ($(window).height()+ $(document).scrollTop()+1>=$(document).height()) {
                        //滚动到当前文档底部,并且是否还有页数可以显示 有则继续查询出来显示
                        if(currentPage <= pages){
                            query();
                            //滚动到底部时,如果此时还有页数 弹出加载中信息
                            $(document).dialog({
                                type : 'notice',
                                infoText: '加载中',
                                autoClose: 1500,
                                position: 'center'  // center: 居中; bottom: 底部
                            });
                        }else{
                            //滚动到当前文档底部,如果已经是最后一页 则弹出已经到底
                            $(document).dialog({
                                type : 'notice',
                                infoText: '亲,已经到底了',
                                autoClose: 1500,
                                position: 'bottom'  // center: 居中; bottom: 底部
                            });
                        }
                    }
                });





                /*$.get("/users/" + user.id+"/orders", {pageSize: 5, type: 2}, function (data) {
                    console.log(data);
                    $("#dingdan").renderValues(data,{
                        getSum:function (item,value) {
                            var number = $(item).closest("a").find("em").html();
                            $(item).html(number*value);

                        }
                    });
                })*/
            }else{

            }
        })
    </script>

</head>
<body>
<section class="aui-flexView">
    <header class="aui-navBar aui-navBar-fixed b-line">
        <a href="/mine/store/shop.html" class="aui-navBar-item">
            <i class="icon icon-return"></i>
        </a>
        <div class="aui-center">
            <span class="aui-center-title">我的订单</span>
        </div>
    </header>
    <br>
    <br>


    <div class="aui-tab" data-ydui-tab="">
        <div class="tab-panel">
            <!--订单-->
            <div class="divHeight"></div>

            <div class="tab-panel" id="dingdan">
                <div class="tab-panel-item tab-active"  render-loop="list">
                    <div class="tab-item">
                        <div class="aui-mail-product b-line">
                            <a href="javascript:;" class="aui-mail-product-item">
                                <div class="aui-mail-product-item-hd">
                                    <img render-src="list.product.imgUrls">
                                </div>
                                <div class="aui-mail-product-item-bd">
                                    <p render-html="list.product.info"></p>
                                </div>
                                <div class="aui-mail-product-right">
                                    <h4 render-html="list.product.integral"></h4><span>积分</span>
                                </div>
                            </a>
                        </div>
                        <a href="javascript:;" class="aui-mail-payment">
                            <p>
                                共<em render-html="list.number"></em>
                                件商品 实付款: <i render-key="list.product.integral" render-fun="getSum"></i>积分
                            </p>
                        </a>
                        <div class="aui-mail-button">
                            <a class="aui-well-item aui-well-item-clear b-line"  style="border: 1px solid #00bbd3; background: #f5f5f5">
                                <div class="aui-well-item-bd"></div>
                                <span class="aui-well-item-fr">删除订单</span>
                            </a>
                            <input type="hidden" render-value="list.product.orderId"/>
                            <a class="aui-df-color" render-key="list.product.id" render-fun="getBuyId">再次购买</a>
                        </div>
                        <hr/>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div>
        <div id="aui-mask-box"></div>
        <div id="aui-dialog-box">
            <h3 class="aui-dialog-title">请选择取消订单的理由</h3>
            <label class="cell-item">
                <label class="cell-right">
                    <input type="radio" value="2" name="checkbox">
                    <i class="cell-checkbox-icon"></i>
                </label>
                <span class="cell-left">收货人信息有误</span>
            </label>
            <label class="cell-item">
                <label class="cell-right">
                    <input type="radio" value="2" name="checkbox">
                    <i class="cell-checkbox-icon"></i>
                </label>
                <span class="cell-left">商品数量或款式需调整</span>
            </label>
            <label class="cell-item">
                <label class="cell-right">
                    <input type="radio" value="2" name="checkbox">
                    <i class="cell-checkbox-icon"></i>
                </label>
                <span class="cell-left">有更优惠的购买方案</span>
            </label>
            <label class="cell-item">
                <label class="cell-right">
                    <input type="radio" value="2" name="checkbox">
                    <i class="cell-checkbox-icon"></i>
                </label>
                <span class="cell-left">商品缺货</span>
            </label>
            <label class="cell-item">
                <label class="cell-right">
                    <input type="radio" value="2" name="checkbox">
                    <i class="cell-checkbox-icon"></i>
                </label>
                <span class="cell-left">我不想买了</span>
            </label>
            <label class="cell-item">
                <label class="cell-right">
                    <input type="radio" value="2" name="checkbox">
                    <i class="cell-checkbox-icon"></i>
                </label>
                <span class="cell-left">其他原因</span>
            </label>

            <div class="close1">
                <a href="javascript:void(0)" class="aui-close">取消</a>
                <a href="javascript:void(0)" class="aui-close">确认</a>
            </div>
        </div>
    </div>
</section>
<script>
    $(function () {

    });
</script>
</body>
</html>